package com.itheima.ydd.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 前端需要的数据名称和我们返回的数据名称不一样，需要封装
 * @param <T>
 */

@Data
@NoArgsConstructor
public class PageUtils<T> {
    /**
     * 总数
     */
    private int count;
    /**
     * 总页数
     */
    private int totalPages;
    /**
     * 每页数量
     */
    private int pageSize;

    private int currentPage;
    /**
     * 列表数据
     */
    private List<T> data;

    public PageUtils(IPage<T> page, List<T> data) {
        this.count = (int) page.getTotal();
        this.totalPages = (int) page.getPages();
        this.pageSize = (int) page.getSize();
        this.data = data;
    }

    public PageUtils(IPage<T> page) {
        this.count = (int) page.getTotal();
        this.totalPages = (int) page.getPages();
        this.pageSize = (int) page.getSize();
        this.currentPage = (int) page.getCurrent();
        this.data = page.getRecords();
    }
}
